{extend name="adminblue/base"}
{block name="resources"}
<script src="ADMIN_JS/allselect.js" type="text/javascript"></script>
<script src="ADMIN_JS/rolejs.js" type="text/javascript"></script>
<script src="ADMIN_JS/art_dialog.source.js" type="text/javascript"></script>
<link href="ADMIN_CSS/default1.css" rel="stylesheet" type="text/css">
<link href="ADMIN_CSS/system.css" rel="stylesheet" type="text/css">
<style type="text/css">
.mod-table-main .style0line td input {margin: 3px 0 5px 5px;}
.overflow table td{border-bottom:1px solid #ccc; }
table{width:100%;}
.tr-Current ul{clear:both;}
.tr-Current ul li{float:left;}
.star{color:red;margin-right:10px;}
.aui_title{color:#126AE4;}
.content {position: relative;padding: 10px;}
#EditAllMenuConetnt{margin: 0 0 10px 25px;}
.list-li{line-height:35px;}
.submit01-alert{background: #126AE4;}
.submit01-alert:hover{background: #0059d6;border:1px solid #0059d6;}
#gray-edit-role .btn,#gray-add-role .btn{display: block;}
.user-group-name{margin-right:10px;}
i.left-10{margin-left:6px;}
.ns-main{margin-top:0px;}
</style>
{/block}
{block name="main"}
<div class="options-btn">
	<button id="addrole" class="btn-common">添加用户组</button>
</div>
<table class="table-class">
	<colgroup>
		<col style="width: 2%;">
		<col style="width: 78%;">
		<col style="width: 10%;">
		<col style="width: 10%;">
	</colgroup>
	<thead>
		<tr align="center">
			<th><i class="checkbox-common"><input id="ckall" type="checkbox" class="input-common" onclick="CheckAll(this)" /></i></th>
			<th style="text-align: left;">用户组</th>
			<th>是否是管理员组</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="grouplis" style="font-size: 12px;"></tbody>
</table>
<input type="hidden" id="hidden_rolename" />
<input type="hidden" name="sendCheckDatas" id="sendCheckDatas">
<script type="text/javascript">
function open_UpdateRoleManage(module_id_array, roleId, name) {
	
	$('#update_user').modal('show');
	//popupOperate("gray-edit-role", "用户组设置", "gray-edit-role");
	$("#currentRoleID").val(roleId);
	$("#EditRoleName").val(name);
	if (roleId == 1) {
		$("[name = permiss]").attr("checked", true);
	} else {
		$("[name = permiss]").attr("checked", false);
		$('input[name = permiss]').each(function() {
			if (module_id_array.indexOf($(this).attr('id')) >= 0) {
				$(this).attr('checked', 'checked').parent().addClass('selected');
			}
		});
	}
}

//修改
function update_RoleManage() {
	var roleId = $("#currentRoleID").val();
	var $roleName = $("#EditRoleName").val();
	var $array = $("#EditsendCheckDatas").val();
	if ($roleName == '') {
		showTip("请填写用户组名称",'warning');
		$("#btn").removeAttr("disabled");
		return;
	}
	if ($array == '') {
		showMessage("error","请选择权限");
		return false;
	}
	$.ajax({
		url : "{:__URL('ADMIN_MAIN/auth/addusergroup')}",
		type : "post",
		data : {
			"roleId" : roleId,
			"array" : $array,
			"roleName" : $roleName
		},
		success : function(res) {
			if(res['code'] > 0){
				window.location.reload();
			}else{
				showTip(res['message'],'error');
			}
		}
	})
}

//删除
function deleteRole(group_id) {
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$(this).dialog('close');
				$.ajax({
				url : "{:__URL('ADMIN_MAIN/auth/deletesystemusergroup')}",
				data : { "group_id" : group_id },
				type : "post",
				dataType : "json",
				success : function(data) {
					if(data['code'] > 0){
						showTip(data['message'],"success");
						window.location.reload();
					}else{
						showTip(data['message'],"error");
					}
				}
			});
		},
		"取消,#f5f5f5,#666": function() {
			$(this).dialog('close');
		}
	},
	contentText:"确定删除吗"
	});
} 

//添加
function add_RoleManage() {
	var $roleName = $("#RoleName").val();
	var array = $("#sendCheckDatas").val();
	if ($roleName == '') {
		showTip("请填写用户组名称",'warning');
		$("#btn").removeAttr("disabled");
		return;
	}

	if (array == '') {
		showTip("请选择权限","warning");
		$("#btn").removeAttr("disabled");
		return;
	}
	$.ajax({
		url : "{:__URL('ADMIN_MAIN/auth/addusergroup')}",
		type : "post",
		data : {
			"array" : array,
			"roleName" : $roleName
		},
		success : function(res) {
			if(res['code'] > 0){
				window.location.reload();
			}else{
				showTip(res['message'],"error");
				$("#btn").removeAttr("disabled");
			}
		}
	})
}

//查询 pageNum：显示那一页   where：条件
function LoadingInfo(page_index) {
	$.ajax({
		url : "{:__URL('ADMIN_MAIN/auth/authgrouplist')}",
		type : "post",
		data : { "page_index" : page_index, "page_size" : $("#showNumber").val() },
		dataType : "json",
		success : function(res) {
			$("#grouplis").children("tr").remove();
			for (var i = 0; i < res['data'].length; i++) {
				var array = res['data'][i];
				var name = array["group_name"];
				var roleId = array["group_id"];
				var is_system = array["is_system"];
				var module_id_array = array['module_id_array'];
				if(is_system == 0){
					var is_system_name = '否';
				}else{
					var is_system_name = '是';
				}
				$("#hidden_rolename").val($("#hidden_rolename").val() + "," + name);
				var strBeg = "<tr class='tr-Current' align='center'><td><i class='checkbox-common'><input name='sub' class='input-common' type='checkbox' value="
					+ roleId
					+ " is_system="
					+ is_system
					+ " onclick='CheckThis()'>";
				strBeg = strBeg
					+ "</i></td><td align='left'><div class='cell'>"
					+ name
					+ "</div></td><td>"
					+ is_system_name
					+ "</td>";
				if(is_system == 0){
					strBeg = strBeg
					+ "<td><div class='cell'><div class='mod-operate'><div class='con style0editel'><a class='edit' href='javascript:void(0)' onclick='open_UpdateRoleManage(&#39;"
					+ module_id_array
					+ "&#39;,"
					+ roleId
					+ ",&#39;"
					+ name
					+ "&#39;)'>编辑</a>  <a class='del' href='javascript:void(0)' onclick='javascript:deleteRole("
					+ roleId + ")'>删除</a>";
				}else{
					strBeg = strBeg
					+ "<td>";
				}
				strBeg = strBeg + "</div></div></div></td></tr>";
				$('#grouplis').append(strBeg);
			}
			initPageData(res["page_count"],res['data'].length,res['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	})
}


function CheckAll(event){
	var checked = event.checked;
	$(".table-class tbody input[type = 'checkbox']").prop("checked",checked);
	if(checked) $(".table-class tbody input[type = 'checkbox']").parent().addClass("selected");
	else $(".table-class tbody input[type = 'checkbox']").parent().removeClass("selected");
}

</script>

<!-- 添加权限 -->
<div class="modal fade hide" id="add_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width: 850px;">
	<div class="modal-dialog" >
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3 class="modal-title" id="myModalLabel">用户组添加</h3>
			</div>
			<div class="modal-body">
				<div  class="content scroll">
		<div>
			<div class="mod-form">
				<div class="con style0alert b10">
					<ul class="list-ul">
						<li class="list-li">
							<span class="star">*</span><span class="user-group-name">用户组名称 </span><input type="text" value="" name="RoleName" id="RoleName" class="input-common">
							<span class="prompt"></span>
						</li>
						<li class="list-li">
							<div class="float-l w100"><span class="star">*</span>权限 </div>
							<div class="overflow">
								<ul id="AllMenuConetnt">
									<li id="contentPaltForm">
										<label>
											<i class="checkbox-common">
											<input id="Add01" name="import" style="margin: -1px 0 0;" dir="title" type="checkbox" onclick="AllCheckBoxClick(event);">
											</i>
											<span>平台</span>
										</label>
										<div class="mod-table l30">
											<div class="mod-table-main">
												<div class="con style0line" style="padding-left: 9px;">
													<table class="table table-hover">
														<colgroup>
															<col style="width: 10%;">
															<col style="width: 90%;">
														</colgroup>
														<tbody id="platFormContent">
															{foreach item="vo" name="list"}
															<tr class="tr-Current">
																<td>
																	<div>
																		<label>
																			<i class="checkbox-common">
																			<input type="checkbox" name="add_per" dir="parent" id="{$vo.module_id}" value="{$vo.module_id}" onclick="AllCheckBoxClick(event);" /></i>&nbsp;{$vo.module_name}
																		</label>
																	</div>
																</td>
															<td>
															{foreach item="per" name="vo['child']"}
																<ul class="second">
																	<li style="margin-right:10px;">
																		<div class="cell">
																			<label class="w120">
																				<i class="checkbox-common">
																				<input type="checkbox" name="add_per" dir="son" id="{$per.module_id}" value="{$per.module_id}" onclick="AllCheckBoxClick(event);" />&nbsp;
																				</i>
																				<span style="font-weight:normal;color:#000;">{$per.module_name}</span>
																			</label>
																		</div>
																	</li>
																	{foreach item="three" name="per['child']"} 
																	<li>
																		<div class="cell">
																			<label class="w120">
																				<i class="checkbox-common left-10">
																				<input type="checkbox" name="add_per" dir="sonson" id="{$three.module_id}" value="{$three.module_id}" onclick="AllCheckBoxClick(event);" />&nbsp;
																				</i>
																				<span style="font-weight:normal;color:#666;">{$three.module_name}</span>
																			</label>
																		</div>
																	</li>
																	{/foreach}
																</ul>
															{/foreach}
															</td>
														</tr>
														{/foreach}
														</tbody>
													</table>
												</div>
											</div>
										</div>
									</li>
								</ul>
							</div>
							<div class="float-l">
								<span class="prompt"></span>
							</div>
						</li>
					</ul>
				</div>
			</div>
			<button class="submit01-alert" style="display: none" id="addSubmit" type="submit">保存</button>
		</div>
	</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn-common btn-big" onclick="btn()">保存</button>
				<button type="button" class="btn-common-cancle btn-big" data-dismiss="modal" onclick="roleClose()">关闭</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改权限 -->

<div class="modal fade hide" id="update_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width: 850px;">
	<div class="modal-dialog" >
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3 class="modal-title" id="myModalLabel">用户组设置</h3>
			</div>
			<div class="modal-body">
				<div  class="content scroll">
		<div>
			<div class="mod-form ">
				<div class="con style0alert b10">
					<ul class="list-ul">
						<li class="list-li">
							<span class="star">*</span>用户组名称
							<input type="text" name="EditRoleName" id="EditRoleName" class="input-common">
							<span class="prompt"></span></li>
						<li class="list-li">
							<div class="float-l w100">
								<span class="star">*</span>权限
							</div>
							<div class="overflow">
								<ul id="EditAllMenuConetnt">
									<li id="EditcontentPaltForm">
										<i class="checkbox-common">
										<input id="Edit01" name="import" dir="top" type="checkbox" style="margin: -1px 0 0;" onclick="EditAllCheckBoxClick(event);">
										</i>
										<span for="Edit01"> 平台</span>
										<div class="mod-table l30">
											<div class="mod-table-main" style="padding-left: 9px;">
												<div class="con style0line">
													<table class="table table-hover">
														<colgroup>
															<col style="width: 10%;">
															<col style="width: 90%;">
														</colgroup>
														<tbody id="EditplatFormContent">
															{foreach item="vo" name="list"}
															<tr class="tr-Current">
																<td>
																	<div>
																		<label>
																			<i class="checkbox-common">
																			<input type="checkbox" name="permiss" dir="parent" id="{$vo.module_id}" value="{$vo.module_id}" onclick="AllCheckBoxClick(event);" /></i>&nbsp;{$vo.module_name}
																			
																		</label>
																	</div>
																</td>
																<td>
																{foreach item="per" name="vo['child']"}
																	<ul class="second">
																		<li style="margin-right:10px;">
																			<div class="cell">
																				<label class="w120">
																					<i class="checkbox-common">
																					<input type="checkbox" name="permiss" dir="son" id="{$per.module_id}" value="{$per.module_id}" onclick="AllCheckBoxClick(event);" />&nbsp;
																					</i>
																					<span style="font-weight:normal;color:#000;">{$per.module_name}</span>
																				</label>
																			</div>
																		</li>
																		{foreach item="three" name="per['child']"} 
																		<li>
																			<div class="cell">
																				<label class="w120">
																					<i class="checkbox-common left-10">
																					<input type="checkbox" name="permiss" dir="sonson" id="{$three.module_id}" value="{$three.module_id}" onclick="AllCheckBoxClick(event);" />&nbsp;
																					</i>
																					<span style="font-weight:normal;color:#666;">{$three.module_name}</span>
																				</label>
																			</div>
																		</li>
																		{/foreach}
																	</ul>
																{/foreach}
																</td>
															</tr>
															{/foreach}
														</tbody>
													</table>
												</div>
											</div>
										</div>
									</li>
								</ul>
							</div>
							<div class="float-l">
								<span class="prompt"></span>
							</div>
						</li>
					</ul>
				</div>
			</div>
			<button type="submit" id="EditSubmit" style="display: none" class="submit01">保存</button>
			<input type="hidden" id="currentRoleID" name="EditRoleID">
			<input type="hidden" name="EditsendCheckDatas" id="EditsendCheckDatas">
		</div>
	</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn-common btn-big" onclick="Editbtn()">保存</button>
				<button type="button" class="btn-common-cancle btn-big" data-dismiss="modal" onclick="btnCancel()">关闭</button>
			</div>
		</div>
	</div>
</div>
{/block}